﻿using System;
using System.Web.UI.WebControls;
using DataObject;
using DataObject.Adv;

namespace KMT.Controls.Common.Adv
{
    public partial class AdvDetail : System.Web.UI.UserControl
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack)
                ListAdv();
        }

        private void ListAdv()
        {
            var lstAdv = AdvController.Adv_GetPartner();
            var count = lstAdv.Count;

            if (count > 0)
            {
                rptAdv.DataSource = lstAdv;
                rptAdv.DataBind();                
            }
        }

        protected void rptAdv_ItemDataBound(object sender, RepeaterItemEventArgs e)
        {
            if (e.Item.ItemType == ListItemType.Item || e.Item.ItemType == ListItemType.AlternatingItem)
            {
                var ltImage = (Literal)e.Item.FindControl("ltImage");
                var advId   = ((HiddenField)e.Item.FindControl("hfAdvId")).Value;                

                var imgHref  = string.Format("{0}/Thumb.ashx?Id={1}&tId={2}&Size={3}", Constants.ThumbImage, advId, (int)CategoryType.Adv, Constants.GetValueFromWebConfig("ThumbAdvDetail"));
                ltImage.Text = string.Format("<img src=\"{0}\" alt=\"\"/>", imgHref);
            }
        }
    }
}